package com.shrct.businessprocess.product.impl;

import com.shrct.businessprocess.organization.RCSupplier;
import com.shrct.businessprocess.organization.impl.RCSupplierImpl;
import com.shrct.businessprocess.product.RCDerivedFullServiceProductSpecification;
import com.shrct.businessprocess.product.RCFullService;
import com.shrct.businessprocess.product.RCFullServiceProductEntry;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.RCLogicProduct;
import com.shrct.businessprocess.product.RCServiceInfo;
import com.shrct.businessprocess.product.RCServiceLevel;
import com.shrct.businessprocess.product.RCServiceResponseTime;
import com.shrct.businessprocess.product.impl.RCDerivedFullServiceProductSpecificationImpl;
import com.shrct.businessprocess.product.impl.RCFullServiceImpl;
import com.shrct.businessprocess.product.proxy.RCFullServiceProductEntryProxy;
import edu.fudan.langlab.domain.common.DateRange;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import edu.fudan.mylang.utils.DateUtil;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCFULLSERVICEPRODUCTENTRY_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcfullserviceproductentry")
public class RCFullServiceProductEntryImpl extends BaseModelObject implements RCFullServiceProductEntry {
  public RCFullServiceProductEntryImpl() {
    super();
  }
  
  public RCFullServiceProductEntryImpl(final String projectid, final RCFullService fullService) {
    super();
    this.projectid = projectid;;
    this.fullService = fullService;
  }
  
  private String projectid;
  
  public String getProjectid() {
    return this.projectid;
  }
  
  public RCFullServiceProductEntry setProjectid(final String projectid) {
    this.projectid = projectid;
    return this;			
    
  }
  
  private String serviceContractCode;
  
  public String getServiceContractCode() {
    return this.serviceContractCode;
  }
  
  public RCFullServiceProductEntry setServiceContractCode(final String serviceContractCode) {
    this.serviceContractCode = serviceContractCode;
    return this;			
    
  }
  
  @JoinColumn(name = "supplier_id")
  @ManyToOne(targetEntity = RCSupplierImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCSupplier supplier;
  
  public RCSupplier getSupplier() {
    return this.supplier;
  }
  
  public RCFullServiceProductEntry setSupplier(final RCSupplier supplier) {
    this.supplier = supplier;
    return this;			
    
  }
  
  @JoinColumn(name = "type_id")
  @ManyToOne(targetEntity = RCDerivedFullServiceProductSpecificationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCDerivedFullServiceProductSpecification type;
  
  public RCDerivedFullServiceProductSpecification getType() {
    return this.type;
  }
  
  public RCFullServiceProductEntry setType(final RCDerivedFullServiceProductSpecification type) {
    this.type = type;
    return this;			
    
  }
  
  private Date start;
  
  public Date getStart() {
    return this.start;
  }
  
  public RCFullServiceProductEntry setStart(final Date start) {
    this.start = start;
    return this;			
    
  }
  
  private Date end;
  
  public Date getEnd() {
    return this.end;
  }
  
  public RCFullServiceProductEntry setEnd(final Date end) {
    this.end = end;
    return this;			
    
  }
  
  @JoinColumn(name = "fullService_id")
  @ManyToOne(targetEntity = RCFullServiceImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCFullService fullService;
  
  public RCFullService getFullService() {
    return this.fullService;
  }
  
  public RCFullServiceProductEntry setFullService(final RCFullService fullService) {
    this.fullService = fullService;
    return this;			
    
  }
  
  public RCServiceLevel getServiceLevel() {
    RCServiceLevel _serviceLevel = this.type.getServiceLevel();
    return _serviceLevel;
  }
  
  public void setServiceLevel(final RCServiceLevel sl) {
    RCServiceInfo _serviceType = this.type.getServiceType();
    _serviceType.setServiceLevel(sl);
  }
  
  public RCServiceResponseTime getServiceResponseTime() {
    RCServiceResponseTime _serviceResponseTime = this.type.getServiceResponseTime();
    return _serviceResponseTime;
  }
  
  public Integer getServiceDuration() {
    Double _betweenMonth = DateUtil.betweenMonth(this.start, this.end);
    double _plus = ((_betweenMonth).doubleValue() + 0.5);
    int _intValue = Double.valueOf(_plus).intValue();
    return Integer.valueOf(_intValue);
  }
  
  public String getEntityName() {
    RCLogicProduct _sourceProduct = this.fullService.getSourceProduct();
    RCIdentifiablePhysicalProductEntry _currentProduct = _sourceProduct.getCurrentProduct();
    String _sid = _currentProduct.getSid();
    String _plus = ("[" + _sid);
    String _plus_1 = (_plus + "]");
    return _plus_1;
  }
  
  public DateRange getRange() {
    DateRange _dateRange = new DateRange();
    final Procedure1<DateRange> _function = new Procedure1<DateRange>() {
        public void apply(final DateRange it) {
          it.setStartDate(RCFullServiceProductEntryImpl.this.start);
          it.setFinishDate(RCFullServiceProductEntryImpl.this.end);
        }
      };
    DateRange _doubleArrow = ObjectExtensions.<DateRange>operator_doubleArrow(_dateRange, _function);
    return _doubleArrow;
  }
  
  public static RCFullServiceProductEntry create(final String projectid, final RCFullService fullService, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.product.RCFullServiceProductEntry rCFullServiceProductEntry = new com.shrct.businessprocess.product.impl.RCFullServiceProductEntryImpl(
    	projectid,fullService
    );
    objectFactory.create(rCFullServiceProductEntry);
    return rCFullServiceProductEntry;			
    
  }
  
  public static RCFullServiceProductEntry createRCFullServiceProductEntryImpl(final String projectid, final RCFullService fullService, final IObjectFactory objectFactory, final Procedure1<RCFullServiceProductEntry> init) {
    com.shrct.businessprocess.product.RCFullServiceProductEntry rCFullServiceProductEntry = new com.shrct.businessprocess.product.impl.RCFullServiceProductEntryImpl(
    	projectid,fullService
    );
    objectFactory.create(rCFullServiceProductEntry);
    init.apply(rCFullServiceProductEntry);
    
    return rCFullServiceProductEntry;			
    
  }
  
  public RCFullServiceProductEntryProxy toProxy() {
    com.shrct.businessprocess.product.proxy.RCFullServiceProductEntryProxy proxy = new com.shrct.businessprocess.product.proxy.RCFullServiceProductEntryProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
